<template>
  <!-- // 分配角色 -->
  <div>
    <el-checkbox-group v-model="roleIds">
      <el-checkbox
        v-for="item in list"
        :key="item.id"
        :label="item.id"
      >{{ item.name }}</el-checkbox>
    </el-checkbox-group>

    <div style="margin-top: 20px; text-align: right">
      <el-button type="primary" @click="onSave">确定</el-button>
      <el-button @click="closeDialog">取消</el-button>
    </div>
  </div>
</template>
<script>
import { getRolesList } from '@/api/settings'
import { getInfo } from '@/api/user'
import { assignRoles } from '@/api/employees'
export default {
  props: {
    curId: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      roleIds: [],
      list: []
    }
  },
  created() {
    this.loadRolesList()
  },
  methods: {
    async onSave() {
      const res = await assignRoles({ id: this.curId, roleIds: this.roleIds })
      if (res.code !== 10000) return
      this.$message.success(res.message)
      this.$emit('close')
      console.log(res)
    },
    closeDialog() {
      this.$emit('close')
    },
    async loadRolesList() {
      const res = await getRolesList()
      const detail = await getInfo(this.curId)
      console.log(detail)
      this.roleIds = detail.data.roleIds
      this.list = res.data.rows
    }
  }
}
</script>

